home *** CD-ROM | disk | FTP | other *** search
/ OpenGL Superbible (2nd Edition) / OpenGL SuperBible e2.iso / tools / GLUT-3.7 / PROGS / ADA / teapots_procs.adb < prev    next >
Encoding:
Text File  |  1998-08-12  |  7.3 KB  |  179 lines

  1. --
  2. --  (c) Copyright 1993,1994,1995,1996 Silicon Graphics, Inc.
  3. --  ALL RIGHTS RESERVED
  4. --  Permission to use, copy, modify, and distribute this software for
  5. --  any purpose and without fee is hereby granted, provided that the above
  6. --  copyright notice appear in all copies and that both the copyright notice
  7. --  and this permission notice appear in supporting documentation, and that
  8. --  the name of Silicon Graphics, Inc. not be used in advertising
  9. --  or publicity pertaining to distribution of the software without specific,
  10. --  written prior permission.
  11. --
  12. --  THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
  13. --  AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
  14. --  INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
  15. --  FITNESS FOR A PARTICULAR PURPOSE.  IN NO EVENT SHALL SILICON
  16. --  GRAPHICS, INC.  BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
  17. --  SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
  18. --  KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
  19. --  LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
  20. --  THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC.  HAS BEEN
  21. --  ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
  22. --  ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
  23. --  POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
  24. --
  25. --  US Government Users Restricted Rights
  26. --  Use, duplication, or disclosure by the Government is subject to
  27. --  restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
  28. --  (c)(1)(ii) of the Rights in Technical Data and Computer Software
  29. --  clause at DFARS 252.227-7013 and/or in similar or successor
  30. --  clauses in the FAR or the DOD or NASA FAR Supplement.
  31. --  Unpublished-- rights reserved under the copyright laws of the
  32. --  United States.  Contractor/manufacturer is Silicon Graphics,
  33. --  Inc., 2011 N.  Shoreline Blvd., Mountain View, CA 94039-7311.
  34. --
  35. --  OpenGL(TM) is a trademark of Silicon Graphics, Inc.
  36. --
  37.  
  38. with GL; use GL;
  39. with Glut; use Glut;
  40.  
  41. package body Teapots_Procs is
  42.    procedure DoInit is
  43.       ambient : array (0 .. 3) of aliased GLfloat :=
  44.          (0.0, 0.0, 0.0, 1.0);
  45.       diffuse : array (0 .. 3) of aliased GLfloat :=
  46.          (1.0, 1.0, 1.0, 1.0);
  47.       specular : array (0 .. 3) of aliased GLfloat :=
  48.          (1.0, 1.0, 1.0, 1.0);
  49.       position : array (0 .. 3) of aliased GLfloat :=
  50.          (0.0, 3.0, 3.0, 0.0);
  51.  
  52.       lmodel_ambient : array (0 .. 3) of aliased GLfloat :=
  53.          (0.2, 0.2, 0.2, 1.0);
  54.       local_view : aliased GLfloat := 0.0;
  55.    begin
  56.       glLightfv (GL_LIGHT0, GL_AMBIENT, ambient (0)'Access);
  57.       glLightfv (GL_LIGHT0, GL_DIFFUSE, diffuse (0)'Access);
  58.       glLightfv (GL_LIGHT0, GL_POSITION, position (0)'Access);
  59.       glLightModelfv (GL_LIGHT_MODEL_AMBIENT, lmodel_ambient (0)'Access);
  60.       glLightModelfv (GL_LIGHT_MODEL_LOCAL_VIEWER, local_view'Access);
  61.  
  62.       glFrontFace (GL_CW);
  63.       glEnable (GL_LIGHTING);
  64.       glEnable (GL_LIGHT0);
  65.       glEnable (GL_AUTO_NORMAL);
  66.       glEnable (GL_NORMALIZE);
  67.       glEnable (GL_DEPTH_TEST);
  68.       glDepthFunc (GL_LESS);
  69.    end DoInit;
  70.  
  71.    procedure renderTeapot
  72.       (x     : GLfloat; y     : GLfloat; ambr  : GLfloat;
  73.        ambg  : GLfloat; ambb  : GLfloat; difr  : GLfloat;
  74.        difg  : GLfloat; difb  : GLfloat; specr : GLfloat;
  75.        specg : GLfloat; specb : GLfloat; shine : GLfloat)
  76.    is
  77.       mat : array (0 .. 3) of aliased GLfloat;
  78.    begin
  79.       glPushMatrix;
  80.  
  81.       glTranslatef (x, y, 0.0);
  82.  
  83.       mat (0) := ambr;
  84.       mat (1) := ambg;
  85.       mat (2) := ambb;
  86.       mat (3) := 1.0;
  87.       glMaterialfv (GL_FRONT, GL_AMBIENT, mat (0)'Access);
  88.  
  89.       mat (0) := difr;
  90.       mat (1) := difg;
  91.       mat (2) := difb;
  92.       glMaterialfv (GL_FRONT, GL_DIFFUSE, mat (0)'Access);
  93.  
  94.       mat (0) := specr;
  95.       mat (1) := specg;
  96.       mat (2) := specb;
  97.       glMaterialfv (GL_FRONT, GL_SPECULAR, mat (0)'Access);
  98.  
  99.       glMaterialf (GL_FRONT, GL_SHININESS, shine * 128.0);
  100.  
  101.       glutSolidTeapot (1.0);
  102.       glPopMatrix;
  103.    end renderTeapot;
  104.  
  105.    procedure DoDisplay is
  106.    begin
  107.       --  16#4100# = GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT
  108.       glClear (GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
  109.       renderTeapot (2.0, 17.0, 0.0215, 0.1745, 0.0215,
  110.          0.07568, 0.61424, 0.07568, 0.633, 0.727811, 0.633, 0.6);
  111.       renderTeapot (2.0, 14.0, 0.135, 0.2225, 0.1575,
  112.          0.54, 0.89, 0.63, 0.316228, 0.316228, 0.316228, 0.1);
  113.       renderTeapot (2.0, 11.0, 0.05375, 0.05, 0.06625,
  114.          0.18275, 0.17, 0.22525, 0.332741, 0.328634, 0.346435, 0.3);
  115.       renderTeapot (2.0, 8.0, 0.25, 0.20725, 0.20725,
  116.          1.0, 0.829, 0.829, 0.296648, 0.296648, 0.296648, 0.088);
  117.       renderTeapot (2.0, 5.0, 0.1745, 0.01175, 0.01175,
  118.          0.61424, 0.04136, 0.04136, 0.727811, 0.626959, 0.626959, 0.6);
  119.       renderTeapot (2.0, 2.0, 0.1, 0.18725, 0.1745,
  120.          0.396, 0.74151, 0.69102, 0.297254, 0.30829, 0.306678, 0.1);
  121.       renderTeapot (6.0, 17.0, 0.329412, 0.223529, 0.027451,
  122.          0.780392, 0.568627, 0.113725, 0.992157, 0.941176, 0.807843,
  123.          0.21794872);
  124.       renderTeapot (6.0, 14.0, 0.2125, 0.1275, 0.054,
  125.          0.714, 0.4284, 0.18144, 0.393548, 0.271906, 0.166721, 0.2);
  126.       renderTeapot (6.0, 11.0, 0.25, 0.25, 0.25,
  127.          0.4, 0.4, 0.4, 0.774597, 0.774597, 0.774597, 0.6);
  128.       renderTeapot (6.0, 8.0, 0.19125, 0.0735, 0.0225,
  129.          0.7038, 0.27048, 0.0828, 0.256777, 0.137622, 0.086014, 0.1);
  130.       renderTeapot (6.0, 5.0, 0.24725, 0.1995, 0.0745,
  131.          0.75164, 0.60648, 0.22648, 0.628281, 0.555802, 0.366065, 0.4);
  132.       renderTeapot (6.0, 2.0, 0.19225, 0.19225, 0.19225,
  133.          0.50754, 0.50754, 0.50754, 0.508273, 0.508273, 0.508273, 0.4);
  134.       renderTeapot (10.0, 17.0, 0.0, 0.0, 0.0, 0.01, 0.01, 0.01,
  135.          0.50, 0.50, 0.50, 0.25);
  136.       renderTeapot (10.0, 14.0, 0.0, 0.1, 0.06, 0.0, 0.50980392, 0.50980392,
  137.          0.50196078, 0.50196078, 0.50196078, 0.25);
  138.       renderTeapot (10.0, 11.0, 0.0, 0.0, 0.0,
  139.          0.1, 0.35, 0.1, 0.45, 0.55, 0.45, 0.25);
  140.       renderTeapot (10.0, 8.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0,
  141.          0.7, 0.6, 0.6, 0.25);
  142.       renderTeapot (10.0, 5.0, 0.0, 0.0, 0.0, 0.55, 0.55, 0.55,
  143.          0.70, 0.70, 0.70, 0.25);
  144.       renderTeapot (10.0, 2.0, 0.0, 0.0, 0.0, 0.5, 0.5, 0.0,
  145.          0.60, 0.60, 0.50, 0.25);
  146.       renderTeapot (14.0, 17.0, 0.02, 0.02, 0.02, 0.01, 0.01, 0.01,
  147.          0.4, 0.4, 0.4, 0.078125);
  148.       renderTeapot (14.0, 14.0, 0.0, 0.05, 0.05, 0.4, 0.5, 0.5,
  149.          0.04, 0.7, 0.7, 0.078125);
  150.       renderTeapot (14.0, 11.0, 0.0, 0.05, 0.0, 0.4, 0.5, 0.4,
  151.          0.04, 0.7, 0.04, 0.078125);
  152.       renderTeapot (14.0, 8.0, 0.05, 0.0, 0.0, 0.5, 0.4, 0.4,
  153.          0.7, 0.04, 0.04, 0.078125);
  154.       renderTeapot (14.0, 5.0, 0.05, 0.05, 0.05, 0.5, 0.5, 0.5,
  155.          0.7, 0.7, 0.7, 0.078125);
  156.       renderTeapot (14.0, 2.0, 0.05, 0.05, 0.0, 0.5, 0.5, 0.4,
  157.          0.7, 0.7, 0.04, 0.078125);
  158.       glFlush;
  159.    end DoDisplay;
  160.  
  161.  
  162.    procedure ReshapeCallback (w : Integer; h : Integer) is
  163.    begin
  164.       glViewport (0, 0, GLsizei(w), GLsizei(h));
  165.       glMatrixMode (GL_PROJECTION);
  166.       glLoadIdentity;
  167.  
  168.       if w <= h then
  169.          glOrtho (0.0, 16.0, 0.0, GLdouble (16.0*Float (h)/Float (w)),
  170.             -10.0, 0.0);
  171.       else
  172.          glOrtho (0.0, GLdouble (16.0*Float (w)/Float (h)),
  173.             0.0, 16.0, -10.0, 10.0);
  174.       end if;
  175.  
  176.       glMatrixMode (GL_MODELVIEW);
  177.    end ReshapeCallback;
  178. end Teapots_Procs;
  179.